package pl.edu.agh.xls2html.htmlelements;

import static org.junit.Assert.assertEquals;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Before;
import org.junit.Test;

public class CellStyleTest {

	private HSSFWorkbook wb;
	private HSSFSheet sheet;
	private HSSFRow row;
	private HSSFCell cell;
	private HSSFCellStyle style;

	private CellStyle testStyle;

	@Before
	public void setUp() throws Exception {
		wb = new HSSFWorkbook();
		sheet = wb.createSheet();
		row = sheet.createRow(0);
		cell = row.createCell(0);

		style = cell.getCellStyle();
		style.setBorderLeft(HSSFCellStyle.BORDER_DOTTED);
		style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
		style.setBorderTop(HSSFCellStyle.BORDER_THICK);
		style.setBorderBottom(HSSFCellStyle.BORDER_HAIR);

		cell.setCellStyle(style);
		testStyle = new CellStyle(cell, wb);

	}

	@Test
	public void testGetLeftBorderStyle() {

		assertEquals("dotted 1px #000000", testStyle.getLeftBorderStyle());

	}

	@Test
	public void testGetRightBorderStyle() {
		assertEquals("solid 2px #000000", testStyle.getRightBorderStyle());
	}

	@Test
	public void testGetTopBorderStyle() {
		assertEquals("solid 3px #000000", testStyle.getTopBorderStyle());
	}

	@Test
	public void testGetBottomBorderStyle() {
		assertEquals("solid 1px #000000", testStyle.getBottomBorderStyle());
	}

	@Test
	public void testAlignLeftStyle() {
		style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		cell.setCellStyle(style);
		testStyle = new CellStyle(cell, wb);

		assertEquals("left", testStyle.getTextAlign());
	}

	@Test
	public void testAlignRightStyle() {
		style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
		cell.setCellStyle(style);
		testStyle = new CellStyle(cell, wb);
		assertEquals("right", testStyle.getTextAlign());
	}

	@Test
	public void testAlignCenterStyle() {
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		cell.setCellStyle(style);
		testStyle = new CellStyle(cell, wb);
		assertEquals("center", testStyle.getTextAlign());
	}

}
